package com.nado.iims2.blog.dao.notice;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.nado.extensions.sql.SimpleSqlMapDaoSupport;
import com.nado.iims2.blog.model.notice.Notice;

@Repository("NoticeDAO")
public class NoticeDAOImpl extends SimpleSqlMapDaoSupport implements NoticeDAO {
	private final static String PREFIX = "com.nado.iims2.blog.notice.";
	
	@Override
	public List<Notice> selectNoticeList(int offset, int count) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("offset", offset);
		params.put("count", count);
		
		return getSqlMapClient().queryForList(PREFIX + "selectNoticeList", params);
	}

	@Override
	public int selectNoticeListCount() throws SQLException {
		return (Integer) getSqlMapClient().queryForObject(PREFIX + "selectNoticeListCount");
	}

	@Override
	public Notice selectNotice(int noticeNo) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("noticeNo", noticeNo);
		
		return (Notice) getSqlMapClient().queryForObject(PREFIX + "selectNotice", params);
	}

	@Override
	public int updateNotice(Notice model) throws SQLException {
		return getSqlMapClient().update(PREFIX + "updateNotice", model);
	}

	@Override
	public int deleteNotice(Notice model) throws SQLException {
		return getSqlMapClient().update(PREFIX + "deleteNotice", model);
	}

	@Override
	public int insertNotice(Notice model) throws SQLException {
		return getSqlMapClient().update(PREFIX + "insertNotice", model);
	}

}
